package com.pray.praymall.search.controller;

import com.pray.praymall.search.service.MallSearchService;
import com.pray.praymall.search.vo.SearchParamVo;
import com.pray.praymall.search.vo.SearchResultVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * do something
 *
 * @author 魂悸魄
 * @date 2020/9/15 20:48
 */
@Controller
public class SearchController {

    @Resource
    private MallSearchService mallSearchService;

    @GetMapping("/list.html")
    public String listPage(SearchParamVo searchParamVo, Model model, HttpServletRequest request) {
        // 获取路径原生的查询属性
        searchParamVo.set_queryString(request.getQueryString());
        // es检索到的结果传递给页面
        SearchResultVo result = mallSearchService.search(searchParamVo);
        model.addAttribute("result", result);
        return "list";
    }
}
